package com.example.mqtt.dataSource;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.example.mqtt.domain.dataModel;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
//消息源
public class BaseSource implements MessageSource<dataModel> {


    @Override
    public Message<dataModel> receive() {
        dataModel model = new dataModel();
        model.setTs(DateUtil.date());
        model.setValue(RandomUtil.randomDouble(0,10000));
        return MessageBuilder.createMessage(model, new MessageHeaders(new HashMap<>()));

    }
}
